//
//  SEGSystemMessageViewModel.m
//  SEGViewModel
//
//  Created by 乔杨 on 2020/6/9.
//

#import "SEGSystemMessageViewModel.h"
#import "MessageDataBaseModel.h"

@implementation SEGSystemMessageViewModel

- (instancetype)init {
    self = [super init];
    if (self) {
        [self seg_createCommand];
    }
    return self;
}
- (void)seg_createCommand {
    @weakify(self);
    self.command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(NSString *groupId) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            self.dataArray = [[MessageDataBaseModel sharedDataBaseModel] getMessagesDescendingWithGroupId:groupId];
            [subscriber sendNext:@(self.dataArray.count)];
            [subscriber sendCompleted];
            return nil;
        }];
    }];
}

@end
